package com.bw.controller;

import com.bw.entity.MaterialsInfo;
import com.bw.entity.Type;
import com.bw.mapper.MaterialsMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class ListController {


    @Autowired
    MaterialsMapper materialsMapper;

    @RequestMapping("/list.do")
    public String list(MaterialsInfo query, Integer pageNum, Model model) {
        // 渲染下拉框
        List<Type> typeList =  materialsMapper.listType();
        model.addAttribute("typeList",typeList);

        // 开启分页
        PageHelper.startPage(pageNum == null ? 1 : pageNum, 10);
        // 执行查询
        List<MaterialsInfo> list = materialsMapper.list(query);
        // 结果封装为page对象
        PageInfo<MaterialsInfo> pageInfo = new PageInfo<>(list);
        // 把page放入页面
        model.addAttribute("pageInfo", pageInfo);

        // 条件回显

        model.addAttribute("query",query);
        return "list";
    }


}
